﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPWMS.BLL;
using PPWMS.Model;
using Telerik.WinControls.UI;
namespace PPWMS.View
{
    public partial class SubPacking : Telerik.WinControls.UI.RadForm
    {
        #region Fields

        private BLL.Subpack subPackBill = null;
        private Model.SubpackModel subPackModel = null;
        private Model.OrderModel orderModel = null;
        private BLL.Order orderBill = null;
        #endregion

        #region Method

        public SubPacking()
        {
            InitializeComponent();
        }

        public void BindingOrder()
        {
            orderBill = new Order();
            string strWhere = "";
            switch (toolStripComboBoxSubPackFindCondType.Text.Trim())
            {
                case "查询全部": strWhere = "";
                    break;
                case "订单分序号": strWhere = "OrderSubId LIKE '%" + toolStripTextBoxFindKeyWord.Text.Trim() + "%'";
                    break;
                case "产品类别": strWhere = "ProdType  LIKE '%" + toolStripTextBoxFindKeyWord.Text.Trim() + "%'";
                    break;
                case "规格": strWhere = "ProdSpeci LIKE '%" + toolStripTextBoxFindKeyWord.Text.Trim() + "%'";
                    break;
                default:
                    break;
            }
            radGridViewOrders.DataSource = orderBill.GetList(strWhere).Tables[0];
            radGridViewOrders.BestFitColumns();
        }

        public void BindingSubpack()
        {
            subPackBill = new Subpack();
            string strWhere = "";
            switch (toolStripComboBoxSubPackFindCondType.Text.Trim())
            {
                case "查询全部": strWhere = "";
                    break;
                case "订单分序号": strWhere = "OrderSubId LIKE '%" + toolStripTextBoxFindKeyWord.Text.Trim() + "%'";
                    break;
                case "产品类别": strWhere = "ProdType  LIKE '%" + toolStripTextBoxFindKeyWord.Text.Trim() + "%'";
                    break;
                case "规格": strWhere = "ProdSpeci LIKE '%" + toolStripTextBoxFindKeyWord.Text.Trim() + "%'";
                    break;
                default:
                    break;
            }
            radGridViewSubpack.DataSource = subPackBill.GetList(strWhere).Tables[0];
            radGridViewSubpack.BestFitColumns();

        }

        public void SetOrderValue(OrderModel temOrder)
        {
            int OrderSubId = int.Parse(subPackBill.GetMaxSubpackId(temOrder.OrderSubId)) + 1;
            this.radTextBoxSubPackId.Text = temOrder.OrderSubId + "-" + OrderSubId.ToString("D2");
            this.radTextBoxOrderSubId.Text = temOrder.OrderSubId;
            this.radTextBoxOrderId.Text = temOrder.OrderId;
            this.radTextBoxBoxId.Text = temOrder.BoxId;
            this.radTextBoxProdType.Text = temOrder.ProdType;

            if (!string.IsNullOrEmpty(temOrder.SailingDate.ToString()))
            {
                DateTime dt = DateTime.Parse(temOrder.SailingDate.Value.ToShortDateString());
                this.radTextBoxSailingDate.Value = dt;
            }
            this.radTextBoxDestination.Text = temOrder.Destination;
            if (!string.IsNullOrEmpty(temOrder.OutPlanDate.ToString()))
            {
                DateTime dt = DateTime.Parse(temOrder.OutPlanDate.Value.ToShortDateString());
                this.radTextBoxOutPlanDate.Value = dt;
            }
            this.radTextBoxProdSpeci.Text = temOrder.ProdSpeci;
            this.radTextBoxProdDesc.Text = temOrder.ProdDesc;
            this.radTextBoxAddi.Text = temOrder.Addi;
            this.radTextBoxFrameColor.Text = temOrder.FrameColor;
            this.radTextBoxLegType.Text = temOrder.LegType;
            this.radTextBoxMatchedInLeg.Text = temOrder.MatchedInLeg;
            this.radTextBoxFootType.Text = temOrder.FootType;
            this.radTextBoxPanelSpeci.Text = temOrder.PanelSpeci;
            this.radTextBoxPanelFeature.Text = temOrder.PanelFeature;
            this.radTextBoxPanelColor.Text = temOrder.PanelColor;
            this.radTextBoxBoardColor.Text = temOrder.BoardColor;
            this.radTextBoxBoardMaterial.Text = temOrder.BoardMaterial;
            this.radTextBoxEdgeColor.Text = temOrder.EdgeColor;
            this.radTextBoxBackplaneColor.Text = temOrder.BackplaneColor;
            this.radTextBoxChairType.Text = temOrder.ChairType;
            this.radTextBoxChairColor.Text = temOrder.ChairColor;
            this.radTextBoxSpecialTagsRemarks.Text = temOrder.SpecialTagsRemarks;
            this.numericUpDownIncludeItemsFlag.Text = temOrder.IncludeItemsFlag.ToString();
            this.numericUpDownItemsPerPack.Text = temOrder.ItemsPerPack.ToString();
            this.numericUpDownOrderPackCount.Text = temOrder.OrderPackCount.ToString();
            this.numericUpDownTotalItemsCount.Text = temOrder.TotalItemsCount.ToString();
            this.numericUpDownCheckedItemsCount.Text = temOrder.CheckedItemsCount.ToString();
            this.numericUpDownCompletedPackCount.Text = temOrder.CompletedPackCount.ToString();
            this.numericUpDownLackedPackCount.Text = temOrder.LackedPackCount.ToString();
            this.numericUpDownPanelWeight.Text = temOrder.PanelWeight.ToString();
            this.numericUpDownFrameWeight.Text = temOrder.FrameWeight.ToString();
            this.numericUpDownHeight.Text = temOrder.Height.ToString();
            this.numericUpDownNetWeight.Text = temOrder.NetWeight.ToString();
            this.numericUpDownGrossWeight.Text = temOrder.GrossWeight.ToString();
            this.numericUpDownVolume.Text = temOrder.Volume.ToString();
            this.radTextBoxRemark.Text = temOrder.Remark;
        }

        public SubpackModel SetOrderValue()
        {
            SubpackModel temOrder = new SubpackModel();

            temOrder.SubPackId = this.radTextBoxSubPackId.Text;
            temOrder.OrderSubId = this.radTextBoxOrderSubId.Text;
            temOrder.OrderId = this.radTextBoxOrderId.Text;
            temOrder.BoxId = this.radTextBoxBoxId.Text;
            temOrder.ProdType = this.radTextBoxProdType.Text;
            if (!string.IsNullOrEmpty(this.radTextBoxSailingDate.Text))
            {
                DateTime dt = DateTime.Parse(this.radTextBoxSailingDate.Value.ToShortDateString());
                temOrder.SailingDate = dt;
            }
            temOrder.Destination = this.radTextBoxDestination.Text;
            if (!string.IsNullOrEmpty(this.radTextBoxOutPlanDate.Text))
            {
                DateTime dt = DateTime.Parse(this.radTextBoxOutPlanDate.Value.ToShortDateString());
                temOrder.OutPlanDate = dt;
            }
            temOrder.ProdSpeci = this.radTextBoxProdSpeci.Text;
            temOrder.ProdDesc = this.radTextBoxProdDesc.Text;
            temOrder.Addi = this.radTextBoxAddi.Text;
            temOrder.FrameColor = this.radTextBoxFrameColor.Text;
            temOrder.LegType = this.radTextBoxLegType.Text;
            temOrder.MatchedInLeg = this.radTextBoxMatchedInLeg.Text;
            temOrder.FootType = this.radTextBoxFootType.Text;
            temOrder.PanelSpeci = this.radTextBoxPanelSpeci.Text;
            temOrder.PanelFeature = this.radTextBoxPanelFeature.Text;
            temOrder.PanelColor = this.radTextBoxPanelColor.Text;
            temOrder.BoardColor = this.radTextBoxBoardColor.Text;
            temOrder.BoardMaterial = this.radTextBoxBoardMaterial.Text;
            temOrder.EdgeColor = this.radTextBoxEdgeColor.Text;
            temOrder.BackplaneColor = this.radTextBoxBackplaneColor.Text;
            temOrder.ChairType = this.radTextBoxChairType.Text;
            temOrder.ChairColor = this.radTextBoxChairColor.Text;
            temOrder.SpecialTagsRemarks = this.radTextBoxSpecialTagsRemarks.Text;
            if (!string.IsNullOrEmpty(this.numericUpDownIncludeItemsFlag.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownIncludeItemsFlag.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.IncludeItemsFlag = null;
                    }
                    else
                    {
                        temOrder.IncludeItemsFlag = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownItemsPerPack.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownItemsPerPack.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.ItemsPerPack = null;
                    }
                    else
                    {
                        temOrder.ItemsPerPack = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownOrderPackCount.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownOrderPackCount.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.OrderPackCount = null;
                    }
                    else
                    {
                        temOrder.OrderPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownTotalItemsCount.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownTotalItemsCount.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.TotalItemsCount = null;
                    }
                    else
                    {
                        temOrder.TotalItemsCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownCheckedItemsCount.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownCheckedItemsCount.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.CheckedItemsCount = null;
                    }
                    else
                    {
                        temOrder.CheckedItemsCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownCompletedPackCount.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownCompletedPackCount.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.CompletedPackCount = null;
                    }
                    else
                    {
                        temOrder.CompletedPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownCompletedPackCount.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownCompletedPackCount.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.CompletedPackCount = null;
                    }
                    else
                    {
                        temOrder.CompletedPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownLackedPackCount.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownLackedPackCount.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.LackedPackCount = null;
                    }
                    else
                    {
                        temOrder.LackedPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownPanelWeight.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownPanelWeight.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.PanelWeight = null;
                    }
                    else
                    {
                        temOrder.PanelWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownFrameWeight.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownFrameWeight.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.FrameWeight = null;
                    }
                    else
                    {
                        temOrder.FrameWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownHeight.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownHeight.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.Height = null;
                    }
                    else
                    {
                        temOrder.Height = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownNetWeight.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownNetWeight.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.NetWeight = null;
                    }
                    else
                    {
                        temOrder.NetWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownGrossWeight.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownGrossWeight.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.GrossWeight = null;
                    }
                    else
                    {
                        temOrder.GrossWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.numericUpDownVolume.Text))
            {
                int i = -1;
                if (Int32.TryParse(this.numericUpDownVolume.Text, out i))
                {
                    if (i == -1)
                    {
                        temOrder.Volume = null;
                    }
                    else
                    {
                        temOrder.Volume = i;
                    }
                }
            }
            temOrder.Remark = this.radTextBoxRemark.Text;


            return temOrder;
        }

        public OrderModel GetOrderModel(Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            OrderModel temOrder = new OrderModel();

            temOrder.OrderSubId = e.Row.Cells["OrderSubId"].Value.ToString();
            temOrder.OrderId = e.Row.Cells["OrderId"].Value.ToString();
            temOrder.BoxId = e.Row.Cells["BoxId"].Value.ToString();
            temOrder.ProdType = e.Row.Cells["ProdType"].Value.ToString();
            if (!string.IsNullOrEmpty(e.Row.Cells["SailingDate"].Value.ToString()))
            {
                DateTime dt = DateTime.Parse(e.Row.Cells["SailingDate"].Value.ToString());
                temOrder.SailingDate = dt;
            }
            temOrder.Destination = e.Row.Cells["Destination"].Value.ToString();
            if (!string.IsNullOrEmpty(e.Row.Cells["OutPlanDate"].Value.ToString()))
            {
                DateTime dt = DateTime.Parse(e.Row.Cells["OutPlanDate"].Value.ToString());
                temOrder.OutPlanDate = dt;
            }
            temOrder.ProdSpeci = e.Row.Cells["ProdSpeci"].Value.ToString();
            temOrder.ProdDesc = e.Row.Cells["ProdDesc"].Value.ToString();
            temOrder.Addi = e.Row.Cells["Addi"].Value.ToString();
            temOrder.FrameColor = e.Row.Cells["FrameColor"].Value.ToString();
            temOrder.LegType = e.Row.Cells["LegType"].Value.ToString();
            temOrder.MatchedInLeg = e.Row.Cells["MatchedInLeg"].Value.ToString();
            temOrder.FootType = e.Row.Cells["FootType"].Value.ToString();
            temOrder.PanelSpeci = e.Row.Cells["PanelSpeci"].Value.ToString();
            temOrder.PanelFeature = e.Row.Cells["PanelFeature"].Value.ToString();
            temOrder.PanelColor = e.Row.Cells["PanelColor"].Value.ToString();
            temOrder.BoardColor = e.Row.Cells["BoardColor"].Value.ToString();
            temOrder.BoardMaterial = e.Row.Cells["BoardMaterial"].Value.ToString();
            temOrder.EdgeColor = e.Row.Cells["EdgeColor"].Value.ToString();
            temOrder.BackplaneColor = e.Row.Cells["BackplaneColor"].Value.ToString();
            temOrder.ChairType = e.Row.Cells["ChairType"].Value.ToString();
            temOrder.ChairColor = e.Row.Cells["ChairColor"].Value.ToString();
            temOrder.SpecialTagsRemarks = e.Row.Cells["SpecialTagsRemarks"].Value.ToString();
            if (!string.IsNullOrEmpty(e.Row.Cells["IncludeItemsFlag"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["IncludeItemsFlag"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.IncludeItemsFlag = null;
                    }
                    else
                    {
                        temOrder.IncludeItemsFlag = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["ItemsPerPack"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["ItemsPerPack"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.ItemsPerPack = null;
                    }
                    else
                    {
                        temOrder.ItemsPerPack = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["OrderPackCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["OrderPackCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.OrderPackCount = null;
                    }
                    else
                    {
                        temOrder.OrderPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["TotalItemsCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["TotalItemsCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.TotalItemsCount = null;
                    }
                    else
                    {
                        temOrder.TotalItemsCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["CheckedItemsCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["CheckedItemsCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.CheckedItemsCount = null;
                    }
                    else
                    {
                        temOrder.CheckedItemsCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["CompletedPackCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["CompletedPackCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.CompletedPackCount = null;
                    }
                    else
                    {
                        temOrder.CompletedPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["LackedPackCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["LackedPackCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.LackedPackCount = null;
                    }
                    else
                    {
                        temOrder.LackedPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["PanelWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.Row.Cells["PanelWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.PanelWeight = null;
                    }
                    else
                    {
                        temOrder.PanelWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["FrameWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.Row.Cells["FrameWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.FrameWeight = null;
                    }
                    else
                    {
                        temOrder.FrameWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["Height"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.Row.Cells["Height"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.Height = null;
                    }
                    else
                    {
                        temOrder.Height = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["NetWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.Row.Cells["NetWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.NetWeight = null;
                    }
                    else
                    {
                        temOrder.NetWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["GrossWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.Row.Cells["GrossWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.GrossWeight = null;
                    }
                    else
                    {
                        temOrder.GrossWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.Row.Cells["Volume"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.Row.Cells["Volume"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temOrder.Volume = null;
                    }
                    else
                    {
                        temOrder.Volume = i;
                    }
                }
            }
            temOrder.Remark = e.Row.Cells["Remark"].Value.ToString();

            return temOrder;
        }

        public SubpackModel GetOrderModel(RadGridView e)
        {
            SubpackModel temSubpackModel = new SubpackModel();
            temSubpackModel.SubPackId = e.CurrentRow.Cells["SubPackId"].Value.ToString();
            temSubpackModel.OrderSubId = e.CurrentRow.Cells["OrderSubId"].Value.ToString();
            temSubpackModel.OrderId = e.CurrentRow.Cells["OrderId"].Value.ToString();
            temSubpackModel.BoxId = e.CurrentRow.Cells["BoxId"].Value.ToString();
            temSubpackModel.ProdType = e.CurrentRow.Cells["ProdType"].Value.ToString();
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["SailingDate"].Value.ToString()))
            {
                DateTime dt = DateTime.Parse(e.CurrentRow.Cells["SailingDate"].Value.ToString());
                temSubpackModel.SailingDate = dt;
            }
            temSubpackModel.Destination = e.CurrentRow.Cells["Destination"].Value.ToString();
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["OutPlanDate"].Value.ToString()))
            {
                DateTime dt = DateTime.Parse(e.CurrentRow.Cells["OutPlanDate"].Value.ToString());
                temSubpackModel.OutPlanDate = dt;
            }
            temSubpackModel.ProdSpeci = e.CurrentRow.Cells["ProdSpeci"].Value.ToString();
            temSubpackModel.ProdDesc = e.CurrentRow.Cells["ProdDesc"].Value.ToString();
            temSubpackModel.Addi = e.CurrentRow.Cells["Addi"].Value.ToString();
            temSubpackModel.FrameColor = e.CurrentRow.Cells["FrameColor"].Value.ToString();
            temSubpackModel.LegType = e.CurrentRow.Cells["LegType"].Value.ToString();
            temSubpackModel.MatchedInLeg = e.CurrentRow.Cells["MatchedInLeg"].Value.ToString();
            temSubpackModel.FootType = e.CurrentRow.Cells["FootType"].Value.ToString();
            temSubpackModel.PanelSpeci = e.CurrentRow.Cells["PanelSpeci"].Value.ToString();
            temSubpackModel.PanelFeature = e.CurrentRow.Cells["PanelFeature"].Value.ToString();
            temSubpackModel.PanelColor = e.CurrentRow.Cells["PanelColor"].Value.ToString();
            temSubpackModel.BoardColor = e.CurrentRow.Cells["BoardColor"].Value.ToString();
            temSubpackModel.BoardMaterial = e.CurrentRow.Cells["BoardMaterial"].Value.ToString();
            temSubpackModel.EdgeColor = e.CurrentRow.Cells["EdgeColor"].Value.ToString();
            temSubpackModel.BackplaneColor = e.CurrentRow.Cells["BackplaneColor"].Value.ToString();
            temSubpackModel.ChairType = e.CurrentRow.Cells["ChairType"].Value.ToString();
            temSubpackModel.ChairColor = e.CurrentRow.Cells["ChairColor"].Value.ToString();
            temSubpackModel.SpecialTagsRemarks = e.CurrentRow.Cells["SpecialTagsRemarks"].Value.ToString();
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["IncludeItemsFlag"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["IncludeItemsFlag"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.IncludeItemsFlag = null;
                    }
                    else
                    {
                        temSubpackModel.IncludeItemsFlag = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["ItemsPerPack"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["ItemsPerPack"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.ItemsPerPack = null;
                    }
                    else
                    {
                        temSubpackModel.ItemsPerPack = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["OrderPackCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["OrderPackCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.OrderPackCount = null;
                    }
                    else
                    {
                        temSubpackModel.OrderPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["TotalItemsCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["TotalItemsCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.TotalItemsCount = null;
                    }
                    else
                    {
                        temSubpackModel.TotalItemsCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["CheckedItemsCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["CheckedItemsCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.CheckedItemsCount = null;
                    }
                    else
                    {
                        temSubpackModel.CheckedItemsCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["CompletedPackCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["CompletedPackCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.CompletedPackCount = null;
                    }
                    else
                    {
                        temSubpackModel.CompletedPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["LackedPackCount"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["LackedPackCount"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.LackedPackCount = null;
                    }
                    else
                    {
                        temSubpackModel.LackedPackCount = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["PanelWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.CurrentRow.Cells["PanelWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.PanelWeight = null;
                    }
                    else
                    {
                        temSubpackModel.PanelWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["FrameWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.CurrentRow.Cells["FrameWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.FrameWeight = null;
                    }
                    else
                    {
                        temSubpackModel.FrameWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["Height"].Value.ToString()))
            {
                int i = -1;
                if (Int32.TryParse(e.CurrentRow.Cells["Height"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.Height = null;
                    }
                    else
                    {
                        temSubpackModel.Height = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["NetWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.CurrentRow.Cells["NetWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.NetWeight = null;
                    }
                    else
                    {
                        temSubpackModel.NetWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["GrossWeight"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.CurrentRow.Cells["GrossWeight"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.GrossWeight = null;
                    }
                    else
                    {
                        temSubpackModel.GrossWeight = i;
                    }
                }
            }
            if (!string.IsNullOrEmpty(e.CurrentRow.Cells["Volume"].Value.ToString()))
            {
                double i = -1.0000;
                if (Double.TryParse(e.CurrentRow.Cells["Volume"].Value.ToString(), out i))
                {
                    if (i == -1)
                    {
                        temSubpackModel.Volume = null;
                    }
                    else
                    {
                        temSubpackModel.Volume = i;
                    }
                }
            }
            temSubpackModel.Remark = e.CurrentRow.Cells["Remark"].Value.ToString();

            return temSubpackModel;
        }
        #endregion

        #region Event

        private void toolStripButtonSunPackFind_Click(object sender, EventArgs e)
        {
            BindingOrder();
            BindingSubpack();
        }

        private void radGridViewOrders_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            orderModel = GetOrderModel(e);
            SetOrderValue(orderModel);
        }

        private void radButtonOrderAdd_Click(object sender, EventArgs e)
        {
            SubpackModel order = SetOrderValue();
            subPackBill = new Subpack();
            try
            {
                bool isAdd = subPackBill.Add(order);
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加失败");
                throw ex;
            }
            int id = int.Parse(this.radTextBoxSubPackId.Text.Trim().Substring(this.radTextBoxSubPackId.Text.Trim().Length - 2, 2)) + 1;
            this.radTextBoxSubPackId.Text = this.radTextBoxOrderSubId.Text.Trim() + "-" + id.ToString("D2");
            BindingSubpack();
        }

        private void radGridViewSubpack_CommandCellClick(object sender, EventArgs e)
        {
            GridCommandCellElement clickedCommandColumn = sender as GridCommandCellElement;
            subPackBill = new Subpack();
            if (clickedCommandColumn.ColumnInfo.Name == "删除")
            {
                string subPackId = "";
                if (this.radGridViewSubpack.CurrentRow.Cells[0].Value.ToString().Trim() != "")
                {
                    subPackId = this.radGridViewSubpack.CurrentRow.Cells[0].Value.ToString();
                }
                else
                {
                    MessageBox.Show("该产品序号为空，无法删除该产品信息！");
                    return;
                }
                if (subPackBill.Exists(subPackId) == false)
                {
                    MessageBox.Show("该产品信息不存在，无法删除该产品信息！");
                    return;
                }
                try
                {
                    string message = "产品信息删除后将无法恢复！ 确定删除该产品信息？";
                    DialogResult dlgrslt = MessageBox.Show(message,
                        "提示对话框",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information);
                    if (dlgrslt == DialogResult.No)
                    {
                        return;
                    }
                    bool isDelete = subPackBill.Delete(subPackId);
                }
                catch { }
            }
            if (clickedCommandColumn.ColumnInfo.Name == "修改")
            {

                subPackModel = GetOrderModel(this.radGridViewSubpack);
                try
                {

                    bool isUpdate = subPackBill.Update(subPackModel);
                }
                catch { }
            }
            BindingSubpack();
        }

        #endregion

    }
}
